<template>
  <div>
    <van-nav-bar
      title="黑马头条-登录"/>
      <van-form @submit="onSubmit">
      <van-field
        v-model="mobile"
        required
        name="mobile"
        label="手机号"
        placeholder="请输入手机号"
        :rules="[{ required: true, message: '请填写手机号' }]"/>
  <van-field
    v-model="password"
    required
    type="password"
    name="code"
    label="验证码"
    placeholder="请输入6位验证码"
    :rules="[{ required: true, message: '请输入6位验证码' }]"
  />
  <div style="margin: 16px;">
    <van-button round block
    type="info"
     native-type="submit"
     :loading="buttonIsLoding"
     :disabled="buttonIsLoding"
     >登录</van-button>
  </div>
</van-form>
  </div>
</template>

<script>
import { mapActions } from 'vuex'
export default {
  name: 'HM-Login',
  data () {
    return {
      mobile: '13888888888',
      password: '246810',
      buttonIsLoding: false
    }
  },
  methods: {
    ...mapActions(['loginActions']),
    async onSubmit (values) {
      // console.log('submit', values)
      try {
        this.buttonIsLoding = true
        const res = await this.loginActions(values)
        console.log(res)
        this.$notify({ type: 'success', message: '登录成功' })
        this.$router.replace('/layout')
      } catch (error) {
        this.$notify({ type: 'danger', message: '登陆失败，请检查您的手机号和密码' })
      }

      this.buttonIsLoding = false
    }
  }
}
</script>

<style scoped>

/* .van-nav-bar {
  background: #007bff;
}
::v-deep .van-nav-bar__title {
  color: white;
} */
</style>
